home *** CD-ROM | disk | FTP | other *** search
- Path: gate.net!mlbfl2-4
- From: bhutto@gate.net (William Hutto)
- Newsgroups: comp.lang.c
- Subject: Re: Binary Tree and MSC/C++7.00
- Date: 8 Jan 1996 02:57:11 GMT
- Organization: CyberGate, Inc.
- Message-ID: <4cq167$kfu@news.gate.net>
- References: <HAKOLA.96Jan7002825@lk-hp-16.hut.fi>
- NNTP-Posting-Host: pslfl2-7.gate.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- In article <HAKOLA.96Jan7002825@lk-hp-16.hut.fi>,
- hakola@snakemail.hut.fi (Petri Hakola) wrote:
- >
- > It seems to me that I suffer some kind of partial amnesia. I
- > can build a binary tree, add stuff to it, but how do I destroy
- > it. I've tried nearly everyting, but there's either General
- > Protection Error or some remains of prior members. I have
- > quite embarassing feeling that I have forget something so
- > obvious that it should almost 'hit the eye', but...
- >
- > if(root == NULL)
- > return;
- > delete_tree(root->left);
- > free(root);
- ^^^^^^^^^^
-
- At this point, is *root* a valid pointer? No.
-
- > delete_tree(root->right);
- ^^^^
- But you use it anyway.
-
- Delete (free) both left and right branches *before* freeing *this* pointer.
- That would hold true for any allocation units pointed to from within *this*
- allocation unit.
-
- >
- > Is this correct or ?
- >
- > And then some problems with strings. Is it common that while
- > coding using Microsoft Programmers Workbench, strings aren't
- > what they're supposed to be. For examble, if I use strncat to
-
- No. 99.9999999% programmer error.
-
- > cut string from 100 char to 45 char, string is cut, but if I
- > print it using printf, first 45 chars come out ok, but rest of
- > the string is filled with smiling faces and all sorts of
- > 'exotic' characters. Like '\0' isn't there or something...
-
- <snip>
-
- Post your code so we can have a look.
-
- Bill
-
- "Whatcha got on?...Your mind?"
-